﻿@using News.Models.Database
@{
	int nowcateId = (int)ViewData["cateId"];
	int nowpage = (int)ViewData["page"];
}
<div id="main">
	<ul id="main_ul">
		@{
			//新闻分类列表
			var cates = ViewData["Cates"] as List<Category>;
			//新闻列表
			var news = ViewData["NewsPosts"] as List<NewsPost>;
			//计算多少页多少行	定义-=>row
			var row = news.Count / 12 + 1;
			//for (int page = 1; page <= row; page++)
			//{
			//分页输出
			//1 2 3 4
			//5 6 7 8
			//9 10 11 12
			//跳过12个、取12个
			var list = news.Skip(((int)ViewData["page"] - 1) * 12).Take(12).ToList();
			foreach (var item in list)
			{
				<li>
					<a href="detail.html?newsID=@item.NewsPId">
						<img src="@item.Photo">
						<p>@item.Title</p>
						<p>
							@item.Content
						</p>
						<p>发布时间:@item.NewsTime</p>
						<p>文章来源:@item.NewsAdd</p>
					</a>
				</li>
			}
			//}
		}
	</ul>
</div>
<div class="paging">
	<div class="paging">
		<ul class="pagination">
			@{
				for (int i = 1; i <= row; i++)
				{
					if (nowpage == i)
					{
						<li><a class="active" href="index.html?cateId=@nowcateId&page=@i">@i</a></li>
					}
					else
					{
						<li><a href="index.html?cateId=@nowcateId&page=@i">@i</a></li>
					}
				}
			}
		</ul>
	</div>
</div>
@section script
	{
	<script src="https://code.jquery.com/jquery-3.6.0.min.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		$(function () {
			$("#search").on("click",
				function () {
					var search_con = $("#content").val();
					if (search_con == "")
						return;
					//
					$.post('/home/Search', { Sea_Content: search_con }, function (data, success) {
						console.log('服务器返回结果：' + data);
						if (data == "ok") {
							window.location.href = "index.html?search_con=" + search_con;
						}
					});

				});
		})
	</script>
}


